import { ErrorHandler, Injectable, Injector, ChangeDetectorRef } from '@angular/core';
import { ToastsManager } from 'ng2-toastr';
import { AppService } from './app.service';

/**
 * Global error handler
 * 
 * Author: Sorin Spiru
 * Date: 15.03.2018
 */
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {

    private toastr: ToastsManager;

    constructor(private inj: Injector) {
        setTimeout(() => {
            this.toastr = this.inj.get(ToastsManager);
        });
    }

    handleError(error) {
        this.toastr.error(error.url, "Error");
        AppService.finishLoading(true);        
    }

}